package com.huiminpay.merchant.controller;

import com.huiminpay.common.cache.util.SecurityUtil;
import com.yh.merchant.api.AppServiceApi;
import com.yh.merchant.dto.AppDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: HWW
 * @Date: 2021/8/2411:16
 * @Desc:
 */
@RestController
@Api("商户应用管理，应用的增删改查")
public class Appcontroller {

    @Reference
    private AppServiceApi appServiceApi;

    @ApiOperation("创建应用")
    @ApiImplicitParam(name="appDTO",value = "应用信息",required = true,dataType = "AppDTO",paramType = "body")
    @PostMapping("/my/apps")
    public AppDTO creatApp(@RequestBody AppDTO appDTO){
        Long merchantId = SecurityUtil.getMerchantId();
        AppDTO app = appServiceApi.createApp(merchantId,appDTO);
        return app;
    }

    @ApiOperation("查询商户的应用")
    @GetMapping("/my/apps")
    public List<AppDTO> findApps(){
        Long merchantId = SecurityUtil.getMerchantId();
        return appServiceApi.findApps(merchantId);
    }

    @ApiOperation("根据用户ID查询商户的应用")
    @GetMapping("/my/apps/{appId}")
    public AppDTO findAppByAppId(@PathVariable("appId") String appId){
        return appServiceApi.findAppByAppId(appId);
    }
}
